﻿using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace GPXCleaner
{
  class GpxSerializer<T> : XmlSerializer
  {
    public GpxSerializer()
      : base(typeof(T))
    {
    }
    public T Deserialize(string xml)
    {
      using (StringReader sr = new StringReader(xml))
      {
        XmlTextReader tr = new XmlTextReader(sr);
        return (T)base.Deserialize(tr);
      }
    }
    public T DeserializeStream(Stream s)
    {
      XmlTextReader tr = new XmlTextReader(s);
      return (T) base.Deserialize(tr);
    }
    public void SerializeStream(T value, Stream s)
    {
      UTF8Encoding utf8 = new UTF8Encoding();
      XmlTextWriter xtw = new XmlTextWriter(s, utf8);
      xtw.Formatting = Formatting.Indented;
      xtw.Indentation = 2;
      base.Serialize(xtw, value);
    }
  }

}
